<template>
    <div class="box"><span>
       

<img src="../assets/tortoise.jpg">

  
</span>

</div>

<div class="textBox">
    <h1>{{course.course_name}}</h1>
    <h3>课程简介：{{course.course_profile}}</h3>
    <h4>课程时长：{{course.course_time}}min &nbsp; &nbsp; &nbsp;
        课程章节：{{course.course_section}}</h4> 
    <h5>任课老师：{{courseDate.tno}}&nbsp; &nbsp; &nbsp;
        开课时间：{{course.begin_time}}&nbsp; &nbsp; &nbsp;
        截止时间：{{course.end_time}}&nbsp; &nbsp; &nbsp;
    </h5>
    <span>点赞量：{{courseDate.add_oil}} &nbsp; &nbsp; &nbsp;
        转发量{{courseDate.repost}} &nbsp; &nbsp; &nbsp;
        评论数：{{courseDate.evaluation}} &nbsp; &nbsp; &nbsp;
        参与人数：{{courseDate.join_person}} &nbsp; &nbsp; &nbsp;</span>
       
</div>
   <div class="buttonBox"> 
        <el-row class="mb-4" style="display:block;margin:0 auto">

   
    <el-button type="primary" round @click="addoil()">点赞</el-button>
    <el-button type="success" round @click="report()">转发</el-button>
    <el-button type="info" round @click="pinglun()">点击评论</el-button>
    <el-button type="warning" round>查看评论</el-button>
    <el-button type="danger" round class="largebutton" @click="choseCourse(course.course_id)">{{buttonstudy}}</el-button>
  </el-row></div>
    
</template>
<script>






    export default{
        data(){
            return{
                course_id:'',
                courseDate:[],
                course:{
                    course_id: 'cxxxx',
                    course_name: '',
                    course_profile:'',
                    course_type:'',
                    course_section: 10,
                    course_time: 0,
                    course_price:0,
                    course_user_id:'',//发布人的编号
                    begin_time:'',
                    update_time:'',
                    end_time:'',
                    course_status:0,//0待审 1审核通过 2审核未通过
                    course_put_status:0, //0未上架 1上架
                },
                buttonstudy:'点击报名',
                addform:{
                    cno:'',
                    course_name:'',
                    sno:0,
                    tno:0,
                }


               
            }
        },
        created(){
            this.getCoursedate()
        },
        methods:{
            async getCoursedate() {
                
                const { data: res } = await this.$http.put(
                    `courseDataDetail/${this.$route.query.id}`
                )
                const { data: res1 } = await this.$http.put(
                    `/selectStudyCno/${window.sessionStorage.getItem('token')}/${this.$route.query.id}`
                )
                if(res1 === 500){
                    this.buttonstudy='继续学习';
                }
                console.log(res)
                if (res === null) {
                return this.$message.error('获取课程数据失败！')
                }
                this.course = res.course
               this.courseDate = res.courseDate
                // this.total = res.data.total
               
            },
      
            choseCourse(course_id){
             
                console.log(window.sessionStorage.getItem('token'))
                this.$router.push({
                    name:'study',
                    query:{
                    id:course_id,
                    tno:this.course.course_user_id,
                    buttonstudy:this.buttonstudy
                    }
                })
            },

            async addoil(){
                this.addform.cno = this.course.course_id
                this.addform.sno = window.sessionStorage.getItem('token')
                this.addform.course_name = this.course.course_name
                this.addform.tno = this.course.course_user_id
                const{data: res} = await this.$http.post("insertAddoil",this.addform)
                if(res===200){
                    this.courseDate.add_oil = this.courseDate.add_oil+1
                }
            },
            async report(){
                this.addform.cno = this.course.course_id
                this.addform.sno = window.sessionStorage.getItem('token')
                this.addform.course_name = this.course.course_name
                this.addform.tno = this.course.course_user_id
                const{data: res} = await this.$http.post("insertReport",this.addform)
                if(res===200){
                    this.courseDate.repost = this.courseDate.repost+1
                }
            },
            pinglun(){
                    alert("稍后再试")
                }
          
        }
        
    }
</script>
<style lang="less" scoped>
.box{
    position: absolute;
    left: 32%;
}
.textBox{
    position: relative;
    top: 45%;
    text-align: center;
}
.buttonBox{
    position: relative;
    top: 48%;
    text-align: center;
}
.largebutton{
    width: 200px;
    height: 100px;
}
</style>